import 'package:flutter/material.dart';

class IntroSliderPage extends StatefulWidget {
  const IntroSliderPage({super.key, this.onNextPressed});

  // Function? onSkipPressed; // 跳过按钮回调
  final Function? onNextPressed; // 跳过按钮回调

  @override
  State<IntroSliderPage> createState() => _IntroSliderPageState();
}

class _IntroSliderPageState extends State<IntroSliderPage> {
  final PageController _pageController = PageController();
  int _currentPage = 0;

  List<Widget> pages = [
    Image.asset('assets/images/splash/guide_1.jpg', fit: BoxFit.cover),
    Image.asset('assets/images/splash/guide_2.jpg', fit: BoxFit.cover),
    Image.asset('assets/images/splash/guide_3.jpg', fit: BoxFit.cover),
  ];
  double size = 10.0;
  double activeSize = 30.0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      body: Stack(
        children: <Widget>[
          PageView.builder(
            physics: const ClampingScrollPhysics(),
            itemCount: pages.length,
            itemBuilder: (context, index) => pages[index],
            controller: _pageController,
            onPageChanged: (int index) {
              setState(() {
                _currentPage = index;
              });
            },
          ),
          // Positioned(
          //     bottom: 10.0,
          //     left: 0.0,
          //     right: 0.0,
          //     child: Align(
          //       alignment: Alignment.bottomCenter,
          //       child: Padding(
          //         padding: const EdgeInsets.only(bottom: 20.0),
          //         child: PageIndicator(
          //           layout: PageIndicatorLayout.warm,
          //           size: size,
          //           activeSize: activeSize,
          //           controller: _pageController,
          //           space: 5.0,
          //           count: pages.length,
          //         ),
          //       ),
          //     )),
          if (_currentPage == pages.length - 1)
            Positioned(
                bottom: 75.0,
                left: 0.0,
                right: 0.0,
                child: Align(
                  alignment: Alignment.bottomCenter,
                  child: Padding(
                      padding: const EdgeInsets.only(bottom: 20.0),
                      child: Container(
                        padding: const EdgeInsets.symmetric(horizontal: 55.0, vertical: 20.0),
                        decoration: BoxDecoration(color: Colors.transparent, borderRadius: BorderRadius.circular(10.0)),
                        child: const Text(
                          '进入APP',
                          style: TextStyle(color: Colors.transparent, fontSize: 16, fontWeight: FontWeight.bold),
                        ),
                      )
                      // .onTap(() {
                      //   AppMainPage.startWithPopAll();
                      //   Storage.setBool(StorageKeys.storageGuide, false);
                      // }),
                      ),
                )),

          Positioned(
              bottom: 0.0,
              left: 0.0,
              right: 0.0,
              child: Align(
                alignment: Alignment.bottomRight,
                child: Padding(
                    padding: const EdgeInsets.only(bottom: 20.0),
                    child: Container(
                      width: 100,
                      padding: const EdgeInsets.symmetric(vertical: 20.0),
                      decoration: const BoxDecoration(color: Colors.transparent),
                      child: const Text(
                        '进入APP',
                        style: TextStyle(color: Colors.transparent, fontSize: 16, fontWeight: FontWeight.bold),
                      ),
                    )
                    // .onTap(() {
                    //   if (_currentPage + 1 == pages.length) {
                    //     // AppMainPage.startWithPopAll();
                    //     // Storage.setBool(StorageKeys.storageGuide, false);
                    //   } else {
                    //     _pageController.animateToPage(_currentPage + 1,
                    //         duration: const Duration(milliseconds: 500), curve: Curves.ease);
                    //   }
                    // }),
                    ),
              )),

          // Skip and Done buttons can be added here
        ],
      ),
    );
  }
}
